<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>菜单管理</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" type="text/css" href="../../easyui/themes/default/easyui.css">
	<script type="text/javascript" src="../../easyui/jquery-1.6.min.js"></script>
	<script type="text/javascript" src="../../easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../easyui/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript" src="../../javascript/tools.js"></script>
	<STYLE>
		.tablestyle01{background-color:#E1EDF7;}
		.tablestyle01 td{ padding:3px 0px 3px 6px; border-bottom:1px dashed #ACB3B9; font-size:12px;}
	</STYLE>
<script type="text/javascript">
		$(function(){
			$("#ul_menu_tree").tree({
				onDblClick: function(node){
					$("#div_config input").each(function(i,n){n.value = "";});
					var msg = getNodeMsg(node);
					for(var key in msg){
						var inp = document.getElementById("inp_"+key);
						if(inp != null){
							inp.value = msg[key];
						}
					}
				}
			});//初始化菜单
			
			initMenuTree();//初始化菜单
		});
		
		function getNodeMsg(node){
			var obj = new Object();
			obj.menuId = node.id;
			obj.menuName = node.text;
			if(node.attributes!=null){
				obj.url = node.attributes.url;
				obj.pxXh = node.attributes.pxXh;
			}
			var pnode = $('#ul_menu_tree').tree('getParent',node.target); 
			if(pnode!=null){
				obj.menuParentId = pnode.id;
				obj.menuParentName = pnode.text;
			}
			return obj;
		}
		
		//初始化功能菜单
		function initMenuTree() {
			$.ajax( {
				type : "POST",
				url : "../menuTree.action",
				dataType : "json",
				success : function(json) {
					var root = json.trees[0];
					root.state = "open";
					root.children[root.children.length - 1].state = "open";
					$("#ul_menu_tree").tree("loadData", json.trees);
				}
			});
		}
		
		function addTree(){
			var node = $("#ul_menu_tree").tree("getSelected");
			if(node==null){
				alert("请选择一个父节点");
				return false;
			}
			var msg = getNodeMsg(node);
			if(msg.url==null || msg.url==""){
				$("#div_config input").each(function(i,n){n.value = "";});
				document.getElementById("inp_menuParentId").value = msg.menuId;
				document.getElementById("inp_menuParentName").value = msg.menuName;
			}else{
				alert("当前所选的节点为功能节点，不能作为父节点");
				return false;
			}
		}
		
		function saveTree(json){
			if(json==null){
				document.getElementById("div_config").action = "treeSave.action";
				
				formSubmit('div_config',saveTree);
			}else{
				document.getElementById("inp_menuId").value = json.tree.menuId;
				initMenuTree();//初始化菜单
				alert("保存成功");
			}
		}
		
		function deleteTree(json){
			if(json==null){
				window.confirm("提示","确认删除?", function(r){
					if(r){
						document.getElementById("div_config").action = "treeDelete.action";
						formSubmit('div_config',deleteTree);
					}
				});
			}else{
				$("#div_config input").each(function(i,n){n.value = "";});
				initMenuTree();//初始化菜单
				alert("删除成功");
			}
		}
		
	</script>
  </head>
  
   <body class="easyui-layout">
  	<div region="north" class="easyui-panel" title="功能树配置" style="height:28px;"></div>
  	<div region="west" class="easyui-panel" split="true" title="功能菜单" style="width:200px;background-color: #E1EDF7;" >
  		<ul id="ul_menu_tree" ></ul>
  	</div>
  	<div id="div_config" region="center" title="配置" class="easyui-panel" style="background-color: #E1EDF7;">
		<table class="tablestyle01" style="margin-top:5px;">
			<tr>
				<td>菜单ID</td>
				<td><input name="tree.menuId" id="inp_menuId" readonly="readonly" style="width: 100%;" /></td>
			</tr>
			<tr>
				<td>上级菜单ID</td>
				<td><input name="tree.menuParentId" id="inp_menuParentId" readonly="readonly" class="easyui-validatebox" required="true" style="width: 100%;" /></td>
			</tr>
			<tr>
				<td>上级菜单名称</td>
				<td><input id="inp_menuParentName" readonly="readonly" class="easyui-validatebox" required="true" style="width: 100%;" /></td>
			</tr>
			<tr>
				<td>排序序号</td>
				<td><input name="tree.pxXh" id="inp_pxXh" class="easyui-validatebox" required="true" validType="number" maxlength="3"  style="width: 100%;"  /></td>
			</tr>
			<tr>
				<td>菜单名称</td>
				<td><input name="tree.menuName" id="inp_menuName" class="easyui-validatebox" required="true" maxlength="100" style="width: 100%;"  /></td>
			</tr>
			<tr>
				<td>连接地址</td>
				<td><input name="tree.url" id="inp_url" class="easyui-validatebox"  maxlength="2000" style="width: 360px;" /></td>
			</tr>
			<tr>
				<td>备忘</td>
				<td style="color: red;">保存时候，判断是否有子节点，有就不能写连接地址，删除判读是不是有子节点  ，删除子节点</td>
			</tr>
		</table>
  	</div>
    <div region="south" class="easyui-panel" align="center" style="height:32px; padding-top: 3px; background-color: #E1EDF7;">
    	<a href="#" class="easyui-linkbutton" onclick="saveTree();">保存</a>
 		<a href="#" class="easyui-linkbutton" onclick="addTree();">新增</a>
 		<a href="#" class="easyui-linkbutton" onclick="deleteTree();">删除</a>
 		<a href="#" class="easyui-linkbutton" onclick="winReload();">刷新</a>
 		<a href="#" class="easyui-linkbutton" onclick="winClose();">关闭</a>
    </div>
  </body>
</html>
